<template>
  <div class="app-container">
  <h2>添加商户</h2>
  <el-form ref="form" :model="form" :rules="rules" label-width="80px">
    <el-form-item label="商家类型" prop="merchantName">
      <el-input v-model="form.merchantName" placeholder="请输入商家类型" />
    </el-form-item>
    <el-form-item label="商户名称" prop="tenantName">
      <el-input v-model="form.tenantName" placeholder="请输入商户名称" />
    </el-form-item>
    <el-form-item label="法人" prop="legalPerson">
      <el-input v-model="form.legalPerson" placeholder="请输入法人" />
    </el-form-item>
    <el-form-item label="省市区" prop="areas">
      <el-cascader
        v-model="form.regions"
        :options="regionList"
        :props="{ expandTrigger: 'hover' }"></el-cascader>
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="form.address" placeholder="请输入地址" />
    </el-form-item>
    <el-form-item label="统一信征码" prop="unifyCode">
      <el-input v-model="form.unifyCode" placeholder="请输入统一信征码" />
    </el-form-item>
    <el-form-item label="身份证" prop="idCard">
      <el-input v-model="form.idCard" placeholder="请输入身份证" />
    </el-form-item>
    <el-form-item label="营业执照" prop="license">
      <el-input v-model="form.license" placeholder="请输入营业执照" />
    </el-form-item>
    <el-form-item label="房产证" prop="ownership">
      <el-input v-model="form.ownership" placeholder="请输入房产证" />
    </el-form-item>
    <el-form-item label="系统用户Id" prop="userId">
      <el-input v-model="form.userId" placeholder="请输入系统用户Id" />
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button type="primary" @click="submitForm">确 定</el-button>
    <el-button @click="cancel">取 消</el-button>
  </div>
  </div>
</template>

<script>
import {addTenant, listTenant, updateTenant} from "@/api/business/tenant";
import {listRegion} from "@/api/house/house";

export default {
  name: "add",
  data() {
    return {
      // 省市县数据
      regionList: [],
      // 表单参数
      form: {
        merchantName: null,
        tenantName: null,
        legalPerson: null,
        regions:[],
        regionId1: null,
        regionId2: null,
        regionId3: null,
        address: null,
        status: null,
        unifyCode: null,
        idCard: null,
        license: null,
        ownership: null,
        userId: null
      },
      // 表单校验
      rules: {
      }
    };
  },
  methods:{
    // 取消按钮
    cancel() {
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        merchantName: null,
        tenantName: null,
        legalPerson: null,
        regions: null,
        address: null,
        status: 0,
        unifyCode: null,
        idCard: null,
        license: null,
        ownership: null,
        createTime: null,
        userId: null
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
            this.form.regionId1 = this.form.regions[0]
            this.form.regionId2 = this.form.regions[1]
            this.form.regionId3 = this.form.regions[2]
            addTenant(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.$router.push('/tenant/list')
            });
        }
      });
    },
    // 省市县
    regionLists(){
      listRegion().then(response => {
        console.log(response)
        this.regionList = response;
      });
    }
  },
  created() {
    this.regionLists()
  }
}
</script>

<style scoped>

</style>
